import { defineStore } from "pinia";
import { getLoginApi } from "../api/user";
// 第一个参数是应用程序中 store 的唯一 id
export const useUsersStore = defineStore("login", {
  // 其它配置项
  state:()=>({
    isAuthenticated: false,
    user: {},
    isToken:""
  }),
  // state: () => {
  //   return { isAuthenticated: false, user: {} };
  // },
  getters: {
    getAuthenticated: (state) => state.isAuthenticated,
    getUser: (state) => state.user,
    getIsToken:(state)=> state.isToken
  },
  actions: {
    setAuth(isAuth) {
      if (isAuth) {
        this.isAuthenticated = isAuth;
      } else {
        this.isAuthenticated = false;
      }
    },
    setUser(user) {
      if (user) {
        this.user = user;
      } else {
        this.user = {};
      }
    },
    setToken(isToken){
      if(isToken){
        this.isToken = isToken
      }else {
        this.isToken = ""
      }
    }
  },
  persist: true
});
